package com.ifeng.stock;



class Parser {
	

	
	/**
	 * parse the stock number in the every pageline
	 * @param pageline
	 * @return
	 */
	 static int parse(String pageline){
		 

		if(pageline.matches(Constants.number_pattern)){

			int endIndex = pageline.indexOf(Constants.suffix);
			String number = pageline.substring(endIndex-6, endIndex);
			
			return Integer.parseInt(number);
		}
	
		return -1;
	}

	 /**
	  * parse the stock name in pageline
	  * @param pageline
	  * @return
	  */
	 static  String parseName(String pageline){

		if( pageline.matches(Constants.name_pattern)){

			int endIndex = pageline.indexOf(Constants.suffix);
			int beginIndex = pageline.indexOf(Constants.prefix) + Constants.prefix.length();
			return pageline.substring(beginIndex, endIndex);
		}
		return null;
	}
	


}
